package com.jin.sys.controller;


import com.jin.sys.common.Constast;
import com.jin.sys.common.DataGridView;
import com.jin.sys.common.TreeNode;
import com.jin.sys.common.WebUtils;
import com.jin.sys.domain.Datas;
import com.jin.sys.domain.Dept;
import com.jin.sys.domain.User;
import com.jin.sys.mapper.DatasMapper;
import com.jin.sys.vo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/datas")
public class DatasController {

    @Autowired
    private DatasMapper datasMapper;


    /**
     *  首页数据接口
     */
    @RequestMapping("loadAllDatas")
    public Datas loadAllDatas() {
        User user = (User) WebUtils.getSession().getAttribute("user");
        Integer studentNumber = this.datasMapper.getStudentNumber();
        Integer leaveNumber = this.datasMapper.getLeaveNumberBySid(user.getId());
        Integer unBackOutLeaveNumber = this.datasMapper.getUnBackOutLeaveNumberBySid(user.getId());
        Integer unApprovedLeaveNumber=0;
        if(user.getType()== Constast.USER_TYPE_TEACHER){
            unApprovedLeaveNumber = this.datasMapper.getUnApproveLeaveNumberByMgr(user.getId());
        }else {
            unApprovedLeaveNumber = this.datasMapper.getUnApproveLeaveNumberByDeptId(user.getDeptid());
        }
        Datas datas = new Datas(studentNumber,leaveNumber,unBackOutLeaveNumber,unApprovedLeaveNumber);
        return datas;
    }
}
